92795f
@@ -136,6 +136,9 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the current builder with the error handler configured
      */
     public RouteBuilder errorHandler(ErrorHandlerBuilder errorHandlerBuilder) {
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("errorHandler must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         setErrorHandlerBuilder(errorHandlerBuilder);
         return this;
@@ -147,6 +150,9 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public InterceptDefinition intercept() {
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("intercept must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.intercept();
     }
@@ -157,6 +163,9 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public InterceptFromDefinition interceptFrom() {
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("interceptFrom must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.interceptFrom();
     }
@@ -168,6 +177,9 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public InterceptFromDefinition interceptFrom(String uri) {
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("interceptFrom must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.interceptFrom(uri);
     }
@@ -179,6 +191,9 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public InterceptSendToEndpointDefinition interceptSendToEndpoint(String uri) {
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("interceptSendToEndpoint must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.interceptSendToEndpoint(uri);
     }
@@ -191,6 +206,10 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public OnExceptionDefinition onException(Class exception) {
+        // is only allowed at the top currently
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("onException must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.onException(exception);
     }
@@ -217,6 +236,10 @@
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
      * @return the builder
      */
     public OnCompletionDefinition onCompletion() {
+        // is only allowed at the top currently
+        if (!routeCollection.getRoutes().isEmpty()) {
+            throw new IllegalArgumentException("onCompletion must be defined before any routes in the RouteBuilder");
+        }
         routeCollection.setCamelContext(getContext());
         return routeCollection.onCompletion();
     }
